import { TAchievementDetatil } from "../../../Message/Db/Tables/TAchievementDetatil";
import { EAcieveCategory } from "../../../Message/Game/EAcieveCategory";
import { TAchievementType } from "../../../Message/Db/Tables/TAchievementType";
import { TAchievementProcessReward } from "../../../Message/Db/Tables/TAchievementProcessReward";
import { AchievementMinorData } from "../view/achievement/data/AchievementMinorData";
import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { TAchievementCategory } from "../../../Message/Db/Tables/TAchievementCategory";
type int = number;
//class AchievementConfig
    
    export  class AchievementConfig
    {
        constructor()
        {
            
            if (AchievementConfig._instance != null) 
            {
                new Error("AchievementConfig单例不能new");
            }
            this.initConfig();
            return;
        }

        public getAchievementDetail(arg1: int, arg2: int, arg3: int): TAchievementDetatil
        {
            var loc1=this.getAchievementKey(arg1, arg2, arg3);
            return this._achievements[loc1];
        }

        public getAchievementDetails(): Map<any, any> /* flash.utils.Dictionary */
        {
            return this._achievements;
        }

        public getAchievementDetailByCode(arg1: int): TAchievementDetatil
        {
            var loc1=null;
            var loc2=0;
            var loc3=this._achievements;
            for(loc1 of loc3) 
            {
                if (loc1.code != arg1) 
                {
                    continue;
                }
                return loc1;
            }
            return null;
        }

        public isImportantAchievement(arg1: int): Boolean
        {
            var loc1=this.getAchievementDetailByCode(arg1);
            if (loc1 == null) 
            {
                return false;
            }
            if (loc1.category == EAcieveCategory._EAchieveCategoryImportant) 
            {
                return true;
            }
            return false;
        }

        public getAchievementType(arg1: int, arg2: int): TAchievementType
        {
            var loc1=this.getAchievementTypeKey(arg1, arg2);
            return this._achievementTypes[loc1];
        }

        public getCategoryName(arg1: int): string
        {
            var loc1=this.getCategoryKey(arg1);
            var loc2=this._categories[loc1];
            if (loc2 == null) 
            {
                return "";
            }
            return loc2.name;
        }

        public getCategoryReward(arg1: int, arg2: int): TAchievementProcessReward
        {
            var loc1=this.getCategoryRewardKey(arg1, arg2);
            return this._categoryRewards[loc1];
        }

        public getMinorAchievementDetailThatFinished(arg1: AchievementMinorData): Array<any>
        {
            var loc2=null;
            var loc1=[];
            var loc3=0;
            var loc4=this._achievements;
            for(loc2 of loc4) 
            {
                if (loc2.category != arg1.category) 
                {
                    continue;
                }
                if (loc2.type != arg1.type) 
                {
                    continue;
                }
                if (loc2.idx > arg1.achievementLevel) 
                {
                    continue;
                }
                loc1.push(loc2);
            }
            return loc1;
        }

        public getAchievmentTotalPoint(): int
        {
            var loc2=null;
            var loc1=0;
            var loc3=0;
            var loc4=this._achievements;
            for(loc2 of loc4) 
            {
                loc1 = loc1 + loc2.point;
            }
            return loc1;
        }

        public getCodesCategories(arg1: Array<any>): Array<any>
        {
            var loc4=0;
            var loc5=null;
            var loc1=[];
            var loc2=0;
            while (loc2 < arg1.length) 
            {
                loc4 = int(arg1[loc2]);
                loc5 = this.getAchievementDetailByCode(loc4);
                loc1[loc5.category] = true;
                ++loc2;
            }
            var loc3=[];
            loc2 = 0;
            while (loc2 < loc1.length) 
            {
                if (Boolean(loc1[loc2])) 
                {
                    loc3.push(loc2);
                }
                ++loc2;
            }
            return loc3;
        }

        /* internal  */initConfig(): void
        {
            this.initAchievements();
            this.initAchievementTypes();
            this.initCategories();
            this.initCategoryRewards();
            return;
        }

        /* internal  */initAchievements(): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            this._achievements = new Map<any, any> /* flash.utils.Dictionary */();
            var loc1=ConfigManager.instance.getJSONByFileName("t_achievement_detatil.json");
            var loc5=0;
            var loc6=loc1;
            for(loc2 of loc6) 
            {
                loc3 = new TAchievementDetatil();
                this.copyValue(loc3, loc2);
                loc4 = this.getAchievementKey(loc3.category, loc3.type, loc3.code);
                this._achievements[loc4] = loc3;
            }
            return;
        }

        /* internal  */getAchievementKey(arg1: int, arg2: int, arg3: int): string
        {
            return arg1.toString() + "_" + arg2.toString() + "_" + arg3.toString();
        }

        /* internal  */initAchievementTypes(): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            this._achievementTypes = new Map<any, any> /* flash.utils.Dictionary */();
            var loc1=ConfigManager.instance.getJSONByFileName("t_achievement_type.json");
            var loc5=0;
            var loc6=loc1;
            for(loc2 of loc6) 
            {
                loc3 = new TAchievementType();
                this.copyValue(loc3, loc2);
                loc4 = this.getAchievementTypeKey(loc3.category, loc3.type);
                this._achievementTypes[loc4] = loc3;
            }
            return;
        }

        /* internal  */getAchievementTypeKey(arg1: int, arg2: int): string
        {
            return arg1.toString() + "_" + arg2.toString();
        }

        /* internal  */initCategories(): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            this._categories = new Map<any, any> /* flash.utils.Dictionary */();
            var loc1=ConfigManager.instance.getJSONByFileName("t_achievement_category.json");
            var loc5=0;
            var loc6=loc1;
            for(loc2 of loc6) 
            {
                loc3 = new TAchievementCategory();
                this.copyValue(loc3, loc2);
                loc4 = this.getCategoryKey(loc3.category);
                this._categories[loc4] = loc3;
            }
            return;
        }

        /* internal  */getCategoryKey(arg1: int): string
        {
            return arg1.toString();
        }

        /* internal  */initCategoryRewards(): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            this._categoryRewards = new Map<any, any> /* flash.utils.Dictionary */();
            var loc1=ConfigManager.instance.getJSONByFileName("t_achievement_process_reward.json");
            var loc5=0;
            var loc6=loc1;
            for(loc2 of loc6) 
            {
                loc3 = new TAchievementProcessReward();
                this.copyValue(loc3, loc2);
                loc4 = this.getCategoryRewardKey(loc3.category, loc3.idx);
                this._categoryRewards[loc4] = loc3;
            }
            return;
        }

        /* internal  */getCategoryRewardKey(arg1: int, arg2: int): string
        {
            return arg1.toString() + "_" + arg2.toString();
        }

        /* internal  */copyValue(arg1: Object, arg2: Object): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=arg2;
            for (loc1 in loc3) 
            {
                arg1[loc1] = arg2[loc1];
            }
            return;
        }

        public static get instance(): AchievementConfig
        {
            if (AchievementConfig._instance == null) 
            {
                AchievementConfig._instance = new AchievementConfig();
            }
            return AchievementConfig._instance;
        }

        /* internal */ /* var */_achievements: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_achievementTypes: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_categories: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_categoryRewards: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: AchievementConfig;
    }
